﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using Millionaire;
using WindowsFormsApplication1.BLL;
using Microsoft.Phone.Shell;

namespace demobackground
{
    public partial class CreateUser : PhoneApplicationPage
    {
        NguoiChoiBLL ncBLL;
        ApplicationBarIconButton btnLuu;
        public CreateUser()
        {
            InitializeComponent();
            ncBLL = new NguoiChoiBLL();
            LoadDataToLbNguoiChoi();
            button1.IsEnabled = false;
            button1.Opacity = 0;
            btnLuu = ApplicationBar.Buttons[0] as ApplicationBarIconButton;
            btnLuu.IsEnabled = false;
        }

        private void btnTao_Click(object sender, RoutedEventArgs e)
        {
            NguoiChoi nc = new NguoiChoi(){
                HoTen = txtTen.Text
            };
            ncBLL.AddNew(nc);
            LoadDataToLbNguoiChoi();
        }
        private void LoadDataToLbNguoiChoi()
        {
            lbNguoiChoi.ItemsSource = ncBLL.GetAll();
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            NguoiChoi nc = (NguoiChoi)lbNguoiChoi.SelectedItem;
            App a = Application.Current as App;
            a.IdNguoiChoi = nc.MaNguoiChoi;
            NavigationService.GoBack();
        }

        private void txtTen_GotFocus(object sender, RoutedEventArgs e)
        {
            txtTen.SelectAll();
        }

        private void lbNguoiChoi_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (lbNguoiChoi.SelectedItems.Count > 0)
            {
                button1.IsEnabled = true;
                btnLuu.IsEnabled = true;
            }
        }

        private void ApplicationBarIconButton_Click_1(object sender, EventArgs e)
        {
            NguoiChoi nc = (NguoiChoi)lbNguoiChoi.SelectedItem;
            App a = Application.Current as App;
            a.IdNguoiChoi = nc.MaNguoiChoi;
            NavigationService.GoBack();
        }
    }
}